Repository navigation
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 49 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
There was a problem hiding this comment.
🟡 Changes recommended
Deserialization still accepts invalid null values and can replace HTTP error exceptions with validation errors, hiding the original status, headers, and body.
2 open issues
What changed in this PR
This PR addresses #339 by tightening response deserialization in both SDK clients, preventing malformed values such as "false" from being coerced into valid authorization results.
Changes:
- Validate container, primitive, and date-input types, raising
FgaValidationExceptionfor mismatches. - Preserve numeric inputs for float fields and existing enum-like model behavior.
- Add async and sync regression tests for malformed responses and valid boolean/list responses.
| File | Description |
|---|---|
test/sync/deserialization_test.py |
Adds synchronous response-validation regression tests. |
test/deserialization_test.py |
Adds asynchronous response-validation regression tests. |
openfga_sdk/sync/api_client.py |
Adds strict type checks to synchronous deserialization. |
openfga_sdk/api_client.py |
Adds matching type checks to asynchronous deserialization. |
Review effort: Balanced (adaptive)
| if not isinstance(data, list): | ||
| raise FgaValidationException( | ||
| f"Invalid response type for `{klass}`: expected a list, got {type(data).__name__}" | ||
| ) |
| if not isinstance(data, dict): | ||
| raise FgaValidationException( | ||
| f"Invalid response type for `{klass.__name__}`: expected a dict, got {type(data).__name__}" | ||
| ) |

Summary
Fixes #339.
Response deserialization no longer coerces incorrectly typed successful responses into plausible values. In particular,
"false"is no longer accepted as a boolean, strings are no longer iterated as lists, and a non-JSON response body is no longer treated as an empty model instance.The async and sync clients now validate JSON container and primitive types while deserializing documented response shapes and raise
FgaValidationExceptionwhen the shape does not match. Numeric JSON values are still accepted forfloatfields, whileintfields reject booleans and non-integers. Enum-like models without typed object properties retain their existing pass-through behavior.Validation:
uv run pytest -q -m 'not integration' --cov-fail-under 60 --cov openfga_sdk test: 657 passed, 12 deselected, 2 subtests passed; coverage 70.83%uv run ruff check .uv run ruff format --check .: 183 files already formatted